package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/4/9 20:17
 * @Version 1.0
 */

@RestController
@RequestMapping("api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService channelService;

    /**
     * 频道列表分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "频道列表分页查询",notes = "author:whn")
    @ApiImplicitParam(name = "dto",value = "请求对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {

        return channelService.listByName(dto);

    }

    /**
     * 新增频道
     * @param entity
     * @return
     */

    @PostMapping
    @ApiOperation(value = "新增频道", notes = "author:whn")
    @ApiImplicitParam(name = "entity",value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult saveWmChannel(@RequestBody WmChannel entity) {

        return channelService.saveWmChannel(entity);

    }

    /**
     * 查询所有的频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {

        List<WmChannel> list = channelService.list();
        return ResponseResult.okResult(list);

    }



}
